<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class AnswerController extends Controller
{
   public function getIndex()
   {	
   		$data = DB::table('answer')
            ->join('issue', 'issue.id', '=', 'answer.Iid')
            ->join('user', 'user.id', '=', 'issue.uid')
            ->select( 'user.name', 'answer.*','issue.atitle')
            ->get();
   		// dd($data);
   		return view('admin.answer.index',['data'=>$data]);
   }

   public function getDel(Request $request)
    {
        //接收数据
        $id = $request->input('id');
          // dd($id);
        //删除
        $res = DB::table('answer')->where('id','=',$id)->delete();

        if($res)
        {
            return redirect('admin/answer/index')->with('success','用户删除成功');
        }else{
            return redirect('admin/answer/index')->with('error','用户删除失败');
        }
    }

    public function getEdit(Request $request)
    {
        //接收数据
        $id = $request->input('id');
         // dd($id);
     
        $res = DB::table('answer')->where('id','=',$id)->get();
        // dd($res);
        // 解析编辑页面
         return view('admin/answer/edit',['res'=>$res]);
       
    }

    // 编辑回复
    public function getUpdate(Request $request)
    {
        $res=$_GET;
        // dd($res);
        
        $data = DB::table('answer')->where('id',$res['id'])
            ->update($res);
            
             // dd($data);

        if($data!=0)
        {
            return redirect('admin/answer/index')->with('success','修改成功');
        }else{
            return back()->withInput()->with('error','修改失败');
        }
     
   }
}